$(function() {
  
    /**
      查询安灯事件
    **/
    function getAanEvents() {
        $.ajax({
                url: '../json/getAanEvents.json',
                type: 'get',
                // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: { method: 'getAanEvents' },
            })
            .done(function(data) {
                console.log("getAanEvents");
                var data = data.data;
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    html += `  <tr>
                                <td class="andonStyle">${data[i].andonStyle}</td>
                                <td class="productlineNum">${data[i].productlineNum}</td>
                                <td class="processId">${data[i].processId}</td>
                                <td class="deviceNum">${data[i].deviceNum}</td>
                                <td class="startTime">${data[i].startTime}</td>
                                <td class="contact"><input type="text"></td>
                                <td class="tel"><input type="text"></td>
                                <td class="contactContent"><input type="text"></td>
                                <td class="remark"><input type="text"></td>
                                <td><button>确认</button></td>
                            </tr>`;
                }
                $(html).appendTo('.table')
                // console.log(html)

            })
            .fail(function() {
                console.log("error");
            })
    }
    getAanEvents();


    function doAanEvenCom(contact, tel, contactContent, remark, startTime, andonStyle) {
        $.ajax({
                url: '../json/getAanEvents.json',
                type: 'get',
                // dataType: 'default: Intelligent Guess (Other values: xml, json, script, or html)',
                data: { 
                    method: 'doAanEvenCom',
                    contact:contact,
                    tel:tel,
                    contactContent:contactContent,
                    remark:remark,
                    startTime:startTime,
                    andonStyle:andonStyle
                }
            })
            .done(function(data) {
                console.log("doAanEvenCom");
                // console.log(html)

            })
            .fail(function() {
                console.log("error");
            })
    }
    $("body").on('click', 'button', function(event) {
        event.preventDefault();
        /* Act on the event */
        var contact=$(this).parent().siblings('.contact').children('input').val();
        var tel=$(this).parent().siblings('.tel').children('input').val();
        var contactContent=$(this).parent().siblings('.contactContent').children('input').val();
        var remark=$(this).parent().siblings('.remark').children('input').val();
        var startTime=$(this).parent().siblings('.startTime').text();
        var andonStyle=$(this).parent().siblings('.andonStyle').text();
        doAanEvenCom(contact, tel, contactContent, remark, startTime, andonStyle);     
    });


})